//
//  LYFriendCell.m
//  artist
//
//  Created by Jay_Apple on 16/3/4.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYFriendCell.h"
#import "LYPostDetailModel.h"
#import "LYImageContentView.h"



@interface LYFriendCell ()

@property (weak, nonatomic) IBOutlet UIImageView *icon;

@property (weak, nonatomic) IBOutlet UILabel *name;

@property (weak, nonatomic) IBOutlet UILabel *information;

@property (nonatomic, weak) UILabel *content;

@property (nonatomic, weak) UIButton *showContentBtn;

@property (nonatomic, weak) LYImageContentView *imageContentV;

@property (weak, nonatomic) IBOutlet UIButton *comment;

@property (weak, nonatomic) IBOutlet UIButton *collection;

@property (weak, nonatomic) IBOutlet UIButton *good;

@end

@implementation LYFriendCell

- (void)awakeFromNib {
    
    //手势
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellIconOnclick:)];
    [self.icon addGestureRecognizer:tap];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
#pragma mark - 懒加载

- (UILabel *)content{
    
    if (_content == nil) {
        UILabel *content = [[UILabel alloc] init];
        content.font = [UIFont systemFontOfSize:14];
        content.textColor = [UIColor colorWithHexString:@"#333333" alpha:1];
        content.numberOfLines = 0;
        [self.contentView addSubview:content];
        
        _content = content;
    }
    
    return _content;
}

- (UIButton *)showContentBtn{

    if (_showContentBtn == nil) {
        UIButton *showContentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [showContentBtn setTitleColor:[UIColor colorWithHexString:@"#FD851F" alpha:1] forState:UIControlStateNormal];
        showContentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
        [showContentBtn addTarget:self action:@selector(showContentBtnOnclick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.contentView addSubview:showContentBtn];
        
        _showContentBtn = showContentBtn;
    }
    
    return _showContentBtn;

}

- (LYImageContentView *)imageContentV{

    if (_imageContentV == nil) {
        LYImageContentView *imageContentV = [[LYImageContentView alloc] init];
        [self.contentView addSubview:imageContentV];
        
        _imageContentV = imageContentV;
    }
    
    return _imageContentV;

}

#pragma mark - 重写
- (void)setModel:(LYPostDetailModel *)model{

    _model = model;
    
    [self.icon setHeader:_model.head_pic];
    self.name.text = _model.nick_name;
    //文字内容
    self.content.text = _model.content;
    self.content.frame = _model.contentF;
    
    //展开按钮
    if (_model.contentOverHeight) {
        
        self.showContentBtn.hidden = NO;
        
        if (_model.showContent) {
            
            [self.showContentBtn setTitle:@"收起" forState:UIControlStateNormal];
            
        }else{
        
            [self.showContentBtn setTitle:@"全文" forState:UIControlStateNormal];
        }
        
        self.showContentBtn.frame = _model.showContentBtnF;
        
    }else{
    
        self.showContentBtn.hidden = YES;
    }
    
    //图片
    if (_model.images.count > 0) {
        
        self.imageContentV.hidden = NO;
        self.imageContentV.model = _model;
        self.imageContentV.frame = _model.imageViewF;
        
    }else{
        
        self.imageContentV.hidden = YES;
    }
    
    //底部数据
    NSString* praise = [NSString stringWithFormat:@"%zd",_model.praise_num];
    NSString *collect = [NSString stringWithFormat:@"%zd",_model.collect_num];
    NSString *comment = [NSString stringWithFormat:@"%zd",_model.comment_num];
    
    [self.comment setTitle:comment forState:UIControlStateNormal];
    [self.good setTitle:praise forState:UIControlStateNormal];
    [self.collection setTitle:collect forState:UIControlStateNormal];
    
    self.collection.selected = _model.is_collect;
    self.good.selected = _model.is_praise;
    
    //时间
    self.information.text = _model.create_time;
    
}

#pragma mark - 按钮点击
/**
 *  全文/收起
 */
- (void)showContentBtnOnclick:(UIButton *)btn{
    
    if ([self.delegate respondsToSelector:@selector(cellShowContentBtnOnclick:)]) {
        
        [self.delegate cellShowContentBtnOnclick:self];
    }

}

/**
 *  底部按钮点击
 */
- (IBAction)bottomBtnOnclick:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(cell:bottomBarBtnOnclickWithType:)]) {
        [self.delegate cell:self bottomBarBtnOnclickWithType:sender.tag];
    }
    
}

/**
 *  头像点击
 */
- (void)cellIconOnclick:(UITapGestureRecognizer *)tap{

    
    if ([self.delegate respondsToSelector:@selector(cellIconOnclick:)]) {
        [self.delegate cellIconOnclick:self];
    }

}



@end
